package cn.edu.sjtu.se.dslab.dao.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.component.Component;
import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IComponentDao;

@Repository("componentDao")
public class ComponentDaoImpl implements IComponentDao {
	private static final String URI = "uri";

	@Resource(name = "baseDao")
	private IBaseDao<Component> baseDao;

	@Override
	public Component queryById(long id) {
		// TODO Auto-generated method stub
		return baseDao.queryById(Component.class, id);
	}

	@Override
	public Component queryByUri(String uri) {
		// TODO Auto-generated method stub
		StringBuffer hql = new StringBuffer();

		// 拼接sql语句
		hql.append("from Component where ");
		hql.append(URI + "=");
		hql.append("'" + uri + "'");
		return baseDao.queryObject(hql.toString());
	}

	@Override
	public boolean checkUri(String uri) {
		// TODO Auto-generated method stub
		Component component = queryByUri(uri);
		if (component != null) {
			return false;
		} else {
			return true;
		}
	}

}
